// components/tab-bar/tar-bar.js
const list1 = function (){
  return [
    { value: 'notice', label: '公告&服务' },
    { value: 'live', label: '实时出勤' },
    { value: 'vehicle', label: '统计查询' },
    { value: 'temp', label: '临时作业' },
  ]
}


Component({

  /**
   * 组件的属性列表
   */
  properties: {
    value: {
      type: String,
      value: 'notice'
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    value: 'notice',
    list: [],
  },


  attached() {
    this.initList();
  },

  /**
   * 组件的方法列表
   */
  methods: {
    initList() {

      //延迟执行
      setTimeout(() => {
        const userInfo = wx.getStorageSync('userinfo'); // 读取缓存中的 usertype
        console.log("userInfo",userInfo)
        const usertype = userInfo.usertype;
        console.log("userInfo",usertype);
        let list;
        if (usertype === '3' || usertype === '4') {
          list = [
            { value: 'notice', label: '公告&服务' },
            { value: 'live_cz', label: '实时出勤' },
            { value: 'vehicle', label: '统计查询' },
            { value: 'temp', label: '临时作业' },
          ];

        } else {
          list = [
            { value: 'notice', label: '公告&服务' },
            { value: 'live', label: '实时出勤' },
            { value: 'vehicle', label: '统计查询' },
            { value: 'temp', label: '临时作业' },
          ];
        }
        this.setData({
          list: list,
        });
      }, 500);




    },


    onChange(e) {
      let value = e.detail.value
      console.log(value)
      this.setData({
        value: value,
      });
      switch (value){
        case 'notice':
          wx.redirectTo({
            url: '/pages/index/index',
          })
          break;
        case 'live':
          wx.redirectTo({
            url: '/pages/live_attendance/live_attendance',
          })
          break;
        case 'live_cz':
          wx.redirectTo({
            url: '/pages/live_attendance_cz/live_attendance_cz',
          })
          break;
        case 'vehicle':
          wx.redirectTo({
            url: '/pages/vehicle/vehicle',
          })
          break;
        case 'temp':
            wx.redirectTo({
              url: '/pages/temp_job/temp_job',
            })
            break;
      }
    },
  }
})